<title>layui 表格、表单函数</title>

<!-- input 标签函数 -->
#define input(name,type,value)
	<input class='layui-input' id='#(name)_id'  type="#(type??'text')" name='#(name??)'  value='#(value??)' lay-verType='tips'/>
#end

<!-- layui form表单默认样式输出函数 start -->
#define colStart(lable,xs)
 		<div class="layui-col-xs12 layui-col-sm6 layui-col-md#(xs??4)">
			<div class="layui-form-item">
				<label class="layui-form-label" #if(labelWidth) style="width:#(labelWidth??110)px" #end for="#(lable??)_id" >#(lable??)#@star()</label>
				<div class="layui-input-block" #if(labelWidth)  style="margin-left:#(labelWidth??110)px" #end>
#end
			
#define colEnd()
				</div>
			</div>
		</div>
#end
<!-- layui div 默认样式输出函数 end -->
	
<!-- 输出星号 -->
#define star()
	#if(req)
		<font color="red">&nbsp;*</font>
		#set(req=false)
	#end
#end

<!-- form提交按钮 -->
#define submitButton()
	#@submitButton2(4)
#end
#define submitButton2(colNum)
 			<div class="layui-row layui-col-space1 task-row">
				<div class="layui-hide-xs layui-col-sm3 layui-col-md#(colNum??4)">
					<div class="layui-input-block"></div>	
				</div>
				<div class="layui-col-xs12 layui-col-sm9 layui-col-md#(12-colNum)">
					<div class="layui-input-block">
							<div class="layui-btn-container" style="margin-top: 10px;margin-left:-25px">
								<button id='submitBtn' type="submit" lay-submit	 class='layui-btn  layui-btn-normal '  value="Submit">
									<i class="layui-icon">&#xe605;</i>	提交
								</button>
								<button id='closeWinBtn' type="button" 	 class='layui-btn  layui-btn-normal  layui-btn-radius' value="Close">
									<i class="layui-icon">&#x1006;</i>	关闭
								</button>
							</div>
					</div>
				</div>
			</div>
			#@submitFunction()   
 #end
 
#define submitFunction()
<!-- 防止重复提交数据 -->
<script type="text/javascript">
		var num=0;
		$('#submitBtn').click(function() {
			if(num==1){
				$('#submitBtn').attr("disabled",true);						
			}
			num=1;
			//解决表单验证不通过的情况
			var timer = window.setInterval(function(){						
				$('#submitBtn').attr("disabled",false);
				num=0;window.clearInterval(timer);
			},3000);
		});
		
		//禁用回车提交事件
		document.onkeypress = function(){
			if(event.keyCode == 13) {
				return false;
			}
		}
</script>
#end
<!-- 分页条件查询表单 start -->
#define formStart()
<form class="layui-form layui-form-pane f-form" id='searchForm' lay-filter='searchForm' action="javascript:;">
	<div class='layui-row layui-col-space1 task-row'>
		<div class='layui-col-xs12 layui-col-sm12 layui-col-md12'> 
			<div class="layui-form-item">
#end
#define formEnd()
				<div class="layui-inline">
					<div class="layui-btn-group">
						<button class="layui-btn layui-btn-disabled" disabled id="searchBtn_">
							<i class="layui-icon">&#xe615;</i>查询
						</button>						
					</div>
				</div>
			</div>
		</div>
	</div>
</form>
#end
<!-- 分页查询表单 end-->

<!-- 条件查询div start -->
#define queryStart(label)
		<div class="layui-inline" style="#(style)">
		    #if(showLabel==true)
			<label class="layui-form-label" for="sex_id">#(label??)</label>
			<div class="layui-input-block">
			#end
#end
#define queryEnd()	
 			#if(showLabel==true)			
			 </div>
			#end
		</div>
#set(style="",showLabel=false)
#end
<!-- 条件查询div end -->

 <!-- 分页列表-->
#define table()
 	<div class='layui-row f-index-toolbar'>
		<div class='layui-col-xs12 layui-col-sm12 layui-col-md12'>
			<div class="layui-btn-group">
				<button id='addBtn_' class="layui-btn layui-btn-normal layui-btn-sm">
				  <i class="layui-icon">&#xe608;</i> 新增
				</button>
				<button id='refreshBtn_' class="layui-btn layui-btn-normal layui-btn-sm">
				  <i class="layui-icon">&#xe669;</i> 刷新
				</button>	
				#@button?()		
				<button id='deleteBtn_' class="layui-btn  layui-btn-normal layui-btn-sm">
				  <i class="layui-icon">&#xe640;</i> 删除
				</button>			
			</div>
		</div>
	</div>	
	<div class="layui-row  f-index-toolbar">
			<div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
				<!-- 默认列表 -->
   				<table id="maingrid" lay-filter="maingrid"></table>
   			</div>
   	</div>
   	<!-- 	每行的操作按钮 -->
	<script type="text/html" id="bar_maingrid">
  	<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
	#@buttonRow?()
  	<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
	</script>
#end

<!-- 表单上传按钮-->
#define formUploadButton(objectId,divId)
	changeDivContent('#(path)/portal/toFormUpload/#(objectId)','#(divId)');
#end

<!-- 是否选项函数 -->
#define getYesOrNo(type,name,title)
	#if(type=='select')
	<select name="#(name)">
			#if(title)
   			<option value="">#(title)</option>
   			#end
   			<option value="1" #if(value==1) selected="selected" #end>#(yesTitle??'是')</option>
   			<option value="0" #if(value==0) selected="selected" #end>#(noTitle??'否')</option>
   	</select>
   	#else
   		<input type="radio" name="#(name)" value="1" #if(value==1) checked="checked" #end  title="#(yesTitle??'是')"/>
   		<input type="radio" name="#(name)" value="0" #if(value==0) checked="checked" #end  title="#(noTitle??'否')"/>
   	#end
#end